package mn.slide.dailynews.tv.adapter;

import java.util.List;

import mn.slide.dailynews.R;
import mn.slide.dailynews.model.TvDayItem;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ItemListAdapter extends ArrayAdapter<TvDayItem>
{
	private List<TvDayItem>	items;
	private Context		context;
	int					layoutResourceId;
	public ItemListAdapter(Context context, int layoutResourceId, List<TvDayItem> items)
	{
		super(context, layoutResourceId, items);
		this.layoutResourceId = layoutResourceId;
		this.items = items;
		this.context = context;
	}
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View row = convertView;
		ItemHolder holder = null;
		if (row == null)
		{
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);
			holder = new ItemHolder();
			holder.itemTextView = (TextView) row.findViewById(R.id.itemTextView);
			row.setTag(holder);
		}
		else
		{
			holder = (ItemHolder) row.getTag();
		}
		TvDayItem item = items.get(position);
		holder.itemTextView.setText(item.name);
		return row;
	}
	public int getCount(){
		return items.size();
	}
	static class ItemHolder
	{
		TextView itemTextView;
	}
}
